<?php

/*
	[Discuz!] (C)2001-2009 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$Id: admingroups.inc.php 17415 2008-12-19 04:34:58Z liuqiang $
*/

if(!defined('IN_SITE') || !defined('IN_ADMIN')) {
	exit('Access Denied');
}
$op = in_array($_GET['op'], array('list', 'edit', 'editsave')) ? $_GET['op'] : 'list';
$actionarray = array(
		'category' => array('add', 'edit', 'list'),
		'content' => array('add', 'edit', 'list', 'del'),
		'recomlist' => array('add','edit'),
		'recommend' => array('add', 'edit', 'list','html'),
		'comment' => array('list','del'),
		'html' => array('index', 'content', 'category'),
		'special' => array('add', 'edit', 'list', 'del'),
		'block' => array('list', 'add', 'edit', 'update', 'disable', 'del'),
		'cache' => array(),
		'user' => array('add', 'edit', 'list', 'dboptimize'),
		'admingroup' => array(),
		'work' => array(),
		'logs' => array(),
		'cron' => array(),
	);
	$operationstr = array(
		'category_lang' => '分类管理',
		'category_add_lang' => '添加分类',
		'category_edit_lang' => '编辑分类',
		'category_list_lang' => '查看分类',
		'content_lang' => '文章管理',
		'content_add_lang' => '添加内容',
		'content_edit_lang' => '编辑内容',
		'content_list_lang' => '查看内容',
		'content_del_lang' => '删除内容',
		'recomlist_lang' => '推荐管理',
		'recomlist_add_lang' => '新增推荐',
		'recomlist_edit_lang' => '修改推荐',
		'recommend_lang' => '查看推荐内容',
		'recommend_add_lang' => '添加推荐内容',
		'recommend_edit_lang' => '编辑推荐内容',
		'recommend_list_lang' => '推荐内容列表',
		'recommend_html_lang' => '生成推荐内容',
		'comment_lang' => '评论管理',
		'comment_list_lang' => '评论列表',
		'comment_del_lang' => '删除评论',
		'html_lang' => '生成管理',
		'html_index_lang' => '生成首页',
		'html_content_lang' => '生成内容页',
		'html_category_lang' => '生成列表页',
		'special_lang' => '专题管理',
		'special_add_lang' => '添加专题',
		'special_edit_lang' => '编辑专题',
		'special_list_lang' => '专题列表 ',
		'special_del_lang' => '删除专题',
		'block_lang' => '碎片管理',
		'block_list_lang' => '碎片列表',
		'block_add_lang' => '添加碎片',
		'block_edit_lang' => '编辑碎片',
		'block_update_lang' => '更新碎片',
		'block_disable_lang' => '碎片启用禁用',
		'block_del_lang' => '删除碎片',
		'cache_lang' => '缓存管理',
		'user_lang' => '系统管理',
		'user_add_lang' => '添加用户',
		'user_edit_lang' => '编辑用户',
		'user_list_lang' => '用户列表',
		'user_dboptimize_lang' => '数据库优化',
		'admingroup_lang' => '用户权限',
		'work_lang' => '工作记录',
		'logs_lang' => '操作记录',
		'cron_lang' => '计划任务',
	);
	$actions = array();
	foreach ($actionarray as $key => $val) {
		$actions[] = $key;
		if(!empty($val) && is_array($val)) {
			foreach ($val as $temp) {
				$actions[] = "{$key}_{$temp}";
			}
		}
	}
switch ($op)
{
	case 'list':
	break;
	
	case 'edit':
		$group = $db->fetch_first("SELECT a.*, aa.disabledactions FROM {$tablepre}admingroups a LEFT JOIN {$tablepre}adminactions aa ON aa.admingid=a.admingid WHERE a.admingid='$groupid'");
		switch($groupid){
			case 1:
				break;
			case 2:
				unset($actions[37]);
				unset($actions[38]);
				unset($actions[39]);
				unset($actions[40]);
				unset($actions[41]);
				unset($actions[42]);
				unset($actions[43]);
				unset($actions[44]);
				unset($actions[45]);
				unset($actions[46]);
				break;
		}
	break;
	
	case 'editsave':
		$dactionarray = array();
			if(is_array($disabled)) {
				foreach($disabled as $key => $value) {
					$key = str_replace("allow", "", $key);
					if(in_array($key, $actions) && !$value) {
						$dactionarray[] = $key;
					}
				}
			}
		$db->query("REPLACE INTO {$tablepre}adminactions (admingid, disabledactions)
				VALUES ('$disabled[admingid]', '".addslashes(serialize($dactionarray))."')");
		$db->update($tablepre.'admingroups',$disabled,"admingid=$disabled[admingid]");
		require_once SITE_ROOT.'./include/cache.func.php';
		$query = $db->query("SELECT a.*,aa.disabledactions FROM {$tablepre}admingroups as a LEFT JOIN {$tablepre}adminactions AS aa ON a.admingid = aa.admingid");
		while($data = $db->fetch_array($query)) {
			writetocache($data['admingid'], '', getcachevars($data), 'admingroup_');
		}
		showmessage('修改成功！', "?action=admingroup&op=edit&groupid=$disabled[admingid]");

}
include admin_tpl("admingroup");
?>